{% load deliverable_tags %}
{% load humanize %}
{% load tagging_tags %}

<div class="deliverables">
  <table class="deliverable">
    <tr>
      <th>Title</th>
      <th>Status</th>
      <th>Owner</th>
      <th>Start Date</th>
      <th>Due Date</th>
      <th>Estimate</th>
      <th>Type</th>
      <th>Objective</th>
      <th>Tags</th>
      <td colspan="2"/>
    </tr>
    {% for deliverable in deliverable_list %}
    <tr>
      <td><a href="{% url deliverable_detail object_id=deliverable.id %}">{{ deliverable.title }}</a></td>
      <td>{% deliverable_status deliverable %}</td>
      <td>{{ deliverable.owner }}</td>
      <td>{{ deliverable.start_date|naturalday }}</td>
      <td>{{ deliverable.target_date|naturalday }}</td>
      <td>
        {% if deliverable.has_bad_estimate %}
          <span class="warning">{{ deliverable.estimate }}</span>
        {% else %}
          {{ deliverable.estimate }}
        {% endif %}
      </td>
      <td>{{ deliverable.type }}</td>
      <td><a href="{% url objective_detail object_id=deliverable.objective.id %}">{{ deliverable.objective }}</a></td>
      <td>
        {% tags_for_object deliverable as tags %} 
        {% for tag in tags %}
          <a href="{% url project_tagged_deliverable tag_name=tag.name %}">{{ tag.name }}</a>
        {% endfor %}
      </td>
      <td>
	{% if deliverable.completed_date %}
        Completed: {{ deliverable.completed_date }}
	<form action="{% url deliverable_set_complete deliverable_id=deliverable.id %}" method="post">
	  <input type="hidden" name="status" value="incomplete" />
	  <input type="submit" value="Incomplete" />
	</form>
	{% endif %}
	{% if not deliverable.completed_date %}
	<form action="{% url deliverable_set_complete deliverable_id=deliverable.id %}" method="post">
	  <input type="hidden" name="status" value="complete" />
	  <input type="submit" value="Complete" />
	</form>
	{% endif %}
      </td>
      <td><a href="{% url deliverable_edit deliverable_id=deliverable.id %}">Edit</td>
    </tr>
    {% endfor %}
  </table>
</div>
